fix: honor offset in non-virtual scrollTo, export scroll config types#57
fix: honor offset in non-virtual scrollTo, export scroll config types#57aojunhao123 wants to merge 7 commits into
Conversation
|
@aojunhao123 is attempting to deploy a commit to the React Component Team on Vercel. A member of the Team first needs to authorize it. |
|
Warning Review limit reached
Next review available in: 55 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (11)
Walkthrough新增 Changes滚动边距与 scrollTo 流程
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant ListyRef
participant useRawListScroll
participant TargetElement
participant Browser
ListyRef->>useRawListScroll: scrollTo(config)
useRawListScroll->>TargetElement: 设置 scrollMarginTop/Bottom
useRawListScroll->>Browser: 调用 scrollIntoView
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #57 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 8 10 +2
Lines 211 211
Branches 62 59 -3
=========================================
Hits 211 211 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Code Review
This pull request introduces support for custom offsets when scrolling to items or group headers in RawList. It refactors the scroll margin application by replacing the CSS-variable-based approach with direct inline styles (scrollMarginTop and scrollMarginBottom) dynamically computed on the target element. It also adds a new "Scroll To" demo, exports relevant types, and updates the test suite to verify the new behavior. There are no review comments, so I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/RawList/useRawListScroll.ts`:
- Around line 69-77: 在 useRawListScroll 中分离 item 与 group 的滚动定位属性:根据 isItem 选择
data-item-key 或 data-group-key 构造选择器,避免继续使用
data-key;同时确保对应的条目和分组节点分别写入匹配的数据属性,并保留现有 applyScrollMargin 的定位行为。
- Around line 39-52: Update applyScrollMargin so sticky header height is
included for item targets whenever align is not 'bottom', including 'auto';
retain zero header offset for bottom alignment and non-item targets.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 41b08372-c439-473b-a4a2-4559168c7b23
📒 Files selected for processing (7)
docs/demos/scroll-to.mddocs/examples/scroll-to.tsxsrc/RawList/index.tsxsrc/RawList/useRawListScroll.tssrc/index.tstests/listy.behavior.test.tsxtests/semantic.test.tsx
这个 PR 在做什么这个 PR 为 RawList 的 item/group 结论不适合合并 存在一个可由合法输入触发的滚动目标混淆问题:item key 与 group key 相同时,会滚动到错误节点。应先拆分两类节点的定位属性并补充回归测试;此外,当前分支与 问题清单🔴 高优先级(阻塞合并)
🟡 中优先级(建议修复)无。 🟢 低优先级(可选改进)无。 |
The virtual list already applied the `offset` from `scrollTo({ key, align,
offset })`, but the non-virtual RawList path ignored it: it set a
`--rc-listy-item-scroll-margin-top` CSS variable that only accounted for the
sticky header height and never the user's offset, and it never set a bottom
margin, so `align: 'bottom'` offsets did nothing.
- RawList now applies `scrollMarginTop`/`scrollMarginBottom` directly on the
scroll target at scroll time (header height + offset for items on `top`
align, offset otherwise), matching the virtual path.
- Drop the CSS-variable indirection and the per-render inline scrollMarginTop
on every item; the margin is applied only on the target, only when scrolling.
- Export `ScrollAlign` and `ListyScrollToConfig` so consumers can type the
config they pass to `scrollTo`.
- Add a `scroll-to` demo exercising both virtual and raw modes.
`align: 'auto'` maps to `scrollIntoView({ block: 'nearest' })`, which can land
the item at the container top where the sticky header would occlude it. The
header offset was only added for `align: 'top'`, so `auto` (and the default)
were left uncorrected in both the raw and virtual paths.
Apply the header offset whenever alignment is not explicitly `bottom`, in both
RawList and VirtualList, keeping the two modes consistent.
62adb9d to
7b6970c
Compare
这个 PR 在做什么PR #57 已 rebase 到包含 #56 的最新 结论不适合合并 RawList 的 offset 实现基本正确,但 VirtualList 对 问题清单🔴 高优先级(阻塞合并)
🟡 中优先级(建议修复)
🟢 低优先级(可选改进)
|
Item keys and group keys shared one namespace in virtual row keys and raw-mode data-key attributes, so a colliding key (an item id equal to a group key) made scrollTo target the wrong node. Row keys are now tagged as `item:x` / `group:x` via a single toTaggedKey helper, stamped once per row at flatten time — which also turns the per-frame itemKey calls in the virtual hot path into plain property reads. Also fixes two edges in the sticky-header offset path: the group lookup map is keyed by tagged keys so a string/number key mismatch can no longer scroll while silently dropping the header compensation, and a falsy group key (0, '') no longer disables the header push-up. Note: raw-mode data-key attribute values change from the raw key to the tagged form (`data-key="item:1"`).
The scrollTo refactor split the single fallthrough into explicit branches; the numeric-offset and position-config paths had no virtual-mode coverage (only raw-mode).
…d align Non-virtual (raw list) scrollTo wrote scroll-margin directly on the target and left it there, permanently overwriting styles.item.scrollMargin*. React diffs the style prop against its own last-rendered value, not the live DOM, so a same-value rerender never restores it. Apply the margin only for the synchronous scrollIntoView call and restore the element's inline value right after. Virtual scrollTo now reads the resolved `align` exposed by the virtual-list offset callback instead of reverse-engineering the direction via getScrollInfo(), adding the sticky-header offset only when the item lands at the top.
Summary
scrollTo({ key, align, offset })already appliedoffsetin the virtual list, but the non-virtual (virtual={false})RawListpath ignored it. It set a--rc-listy-item-scroll-margin-topCSS variable that only accounted for the sticky-header height, never the user'soffset, and it never set a bottom margin — soalign: 'bottom'offsets did nothing at all in non-virtual mode.This PR brings the non-virtual path to parity and tidies up the approach:
offset— it setsscrollMarginTop/scrollMarginBottomdirectly on the scroll target at scroll time (sticky-header height +offsetfor items withalign: 'top',offsetotherwise), matching the virtual list.--rc-listy-item-scroll-margin-top) and the per-render inlinescrollMarginTopon every item. The margin is now applied only on the actual target, and only while scrolling.ScrollAlignandListyScrollToConfigfrom the package entry so consumers can type the config they pass toscrollTo(previously declared but not exported).scroll-todemo that exercises both virtual and raw modes with livealign/offset/ key / group controls.No changes to the public config shape —
offsetwas already a typed option; it simply didn't work in non-virtual mode.Test plan
tests/listy.behavior.test.tsxandtests/semantic.test.tsxupdated and passing (25/25) — assertscrollMarginTop/scrollMarginBottomreflect header height + offset on the target, and that a user-suppliedstyles.item.scrollMarginTopis present at rest but the internal offset wins on the scroll target.tsc --noEmitcleaneslintclean on changed source and the new demoscroll-todemo in both virtual and non-virtual modes🤖 Generated with Claude Code
Summary by CodeRabbit
align: bottom时的滚动落点逻辑。